package com.sxm.indoormanagement.utils;

import com.sxm.indoormanagement.entity.Atmosphere;
import org.jetbrains.annotations.NotNull;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author 780013490@qq.com  孙小明
 * @version 1.0
 * @date 2020/6/13 19:09
 * @description 判断数据时候合法的工具类
 */


public class JudgeDataUtil {
    private static final String pattern = "[0-9]+";


    /**
     * 判断数据是四位数据并且都是数字
     *
     * @param s 数据
     * @return 合法 true  不合法 false
     */
    @NotNull
    public static Boolean isLegal(String s) {
        Pattern r = Pattern.compile(pattern);
        Matcher m = r.matcher(s);
        return (m.matches() && s.length() == 4);
    }

    @NotNull
    public static Atmosphere getData(@NotNull String s) {
        int data;
        data = Integer.parseInt(s);
        Atmosphere atmosphere = new Atmosphere();
        atmosphere.setTemperature(data / 100);
        atmosphere.setHumidity(data % 100);
        return atmosphere;

    }

}
